package com.v1.video.widgets;

import com.v1.video.R;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

public class PortraitMediaPlayerUIController extends MediaPlayerUIController {
	
	public PortraitMediaPlayerUIController(Context context) {
		super(context);
        DisplayMetrics disp = mContext.getResources().getDisplayMetrics();
        mWindowWidth = disp.widthPixels;
        mWindowHeight = mWindowWidth * 9 / 16;
	}

	@Override
	protected View makeControllerLayout() {
		return ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.portrait_media_controller, this);
	}

	@Override
	protected void initControllerView(View contrllerLayout) {
		timeTv = (TextView) contrllerLayout.findViewById(R.id.tv_begin_time);
		lengthTv = (TextView) contrllerLayout.findViewById(R.id.tv_end_time);
		switchLandPortrait = contrllerLayout.findViewById(R.id.iv_video_reverse);
		clickBack = (ImageView) contrllerLayout.findViewById(R.id.iv_result);
		playVideo = (ImageView) contrllerLayout.findViewById(R.id.iv_play);
		seekbar = (SeekBar) contrllerLayout.findViewById(R.id.sb);
		seekbar.setMax(PROGRESS_MAX);
		seekbar.setOnSeekBarChangeListener(mSeekListener);
		
		playVideo.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				   if(mediaPlayer.isPlaying()){
					   updateVideoPalyerUI(false);
				   } else {
					   updateVideoPalyerUI(true);
				   }
				   if(onControllerListener != null){
						onControllerListener.onClick(v);
				   }
			}
		});
		switchLandPortrait.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(onControllerListener != null){
					onControllerListener.onClick(v);
				}
			}
		});
		clickBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(onControllerListener != null){
					onControllerListener.onClick(v);
				}				
			}
		});
	}

	@Override
	protected void setWindow() {
		mPopupWindow.setWidth(mWindowWidth);
		mPopupWindow.setHeight(mWindowHeight);
		mPopupWindow.showAsDropDown(rootView, 0, -mWindowHeight);
	}

}
